#include <bits/stdc++.h>

using namespace std;

int main()
{
    // two dimension
    //  int object_num = 0;
    //  int bag_weight = 0;
    //  cin >> object_num >> bag_weight;
    //  vector<int> object_weight(object_num, 0);
    //  for (int i = 0; i < object_num; i++)
    //  {
    //      cin >> object_weight[i];
    //  }
    //  vector<int> object_value(object_num, 0);
    //  for (int i = 0; i < object_num; i++)
    //  {
    //      cin >> object_value[i];
    //  }
    //  vector<vector<int>> dp(object_num, vector<int>(bag_weight + 1, 0));
    //  for (int j = object_weight[0]; j <= bag_weight; j++)
    //  {
    //      dp[0][j] = object_value[0];
    //  }
    //  for (int i = 1; i < object_num; i++)
    //  {
    //      for (int j = 0; j <= bag_weight; j++)
    //      {
    //          if (j < object_weight[i])
    //          {
    //              dp[i][j] = dp[i - 1][j];
    //          }
    //          else
    //          {
    //              dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - object_weight[i]] + object_value[i]);
    //          }
    //      }
    //  }
    //  cout << dp[object_num - 1][bag_weight] << endl;
    //  return 0;

    // one dimension
    int object_num = 0;
    int bag_weight = 0;
    cin >> object_num >> bag_weight;
    vector<int> object_weight(object_num, 0);
    for (int i = 0; i < object_num; i++)
    {
        cin >> object_weight[i];
    }
    vector<int> object_value(object_num, 0);
    for (int i = 0; i < object_num; i++)
    {
        cin >> object_value[i];
    }
    vector<int> dp(bag_weight + 1, 0);
    for (int i = 0; i < object_num; i++)
    {
        for (int j = bag_weight; j >= object_weight[i]; j--)
        {
            dp[j] = max(dp[j], dp[j - object_weight[i]] + object_value[i]);
        }
    }
    cout << dp[bag_weight] << endl;
    return 0;
}